﻿using MediatR;
using SheepCultivation.Common.Domain.SheepBasicInformation;
using SheepCultivation.Common.Dto;
using SheepCultivation.Common.Infrastructure.Interface;
using SheepCultivation.Enum;

namespace SheepCultivation.API.AddliCation.SheepFile
{
    public class BirthStatusListHandler : IRequestHandler<BirthStatusListCommon, Result>
    {
        public readonly IBaseRepository<BirthStatus> BirthStatusRepository;

        public BirthStatusListHandler(IBaseRepository<BirthStatus> birthStatusRepository)
        {
            BirthStatusRepository = birthStatusRepository;
        }

        public async Task<Result> Handle(BirthStatusListCommon request, CancellationToken cancellationToken)
        {
            var res = new Result() { Code = (int)CommonEnumCode.error };
            try
            {
                var list = BirthStatusRepository.GetAll().ToList();
                res.Code = (int)CommonEnumCode.success;
                res.Data = list;
                res.Msg = "出生状态列表展示";
            }
            catch (Exception)
            {

                throw;
            }

            return res;
        }
    }
}
